package com.cindata

import com.cindata.dictionary.*

class RiskWarning
{
    Account bankAccount
    RiskWarningTypeDict type
    RiskWarningStage stage
    RiskWarningStatusDict status

    Contact contact
    Collateral collateral
    Estate estate
    Mortgage mortgage
    Account account
    Community community

    Boolean isWarning = true

    //还款截止时间
    Date repaymentEndDate

    Date createdDate = new Date()
    Date modifiedDate = new Date()
    User user
    User createBy
    User modifyBy

    // 处置
    RiskWarningDisposalMethod disposalMethod

    Date startTime
    Date endTime

    Date actualStartTime
    Date actualEndTime

    Department disposalDepartment
    User disposalUser
    String description

    // 贷款风险等级
    // RiskWarningLevel riskWarningLevel

    //批量转让
    TransferBatch transferBatch

    Boolean isInWorkflow = false
    Workflow workflow

    static constraints = {

        bankAccount nullable: true, blank: true

        type nullable: true, blank: true
        stage nullable: true, blank: true
        status nullable: true, blank: true
        contact nullable: true, blank: true
        collateral nullable: true, blank: true
        estate nullable: true, blank: true
        mortgage nullable: true, blank: true
        account nullable: true, blank: true
        community nullable: true, blank: true

        createdDate nullable: true, blank: true
        modifiedDate nullable: true, blank: true
        user nullable: true, blank: true
        createBy nullable: true, blank: true
        modifyBy nullable: true, blank: true

        isWarning nullable: true, blank: true

        repaymentEndDate nullable: true, blank: true

        disposalMethod nullable: true, blank: true
        startTime nullable: true, blank: true
        endTime nullable: true, blank: true
        actualStartTime nullable: true, blank: true
        actualEndTime nullable: true, blank: true

        disposalDepartment nullable: true, blank: true
        disposalUser nullable: true, blank: true
        description maxSize: 512, nullable: true, blank: true

        // riskWarningLevel maxSize: 512, nullable: true, blank: true
        transferBatch nullable: true, blank: true

        isInWorkflow nullable: true, blank: true
        workflow nullable: true, blank: true
    }

    def springSecurityService

    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        def user = User.findByUsername(username)
        createBy = user

        if (!stage)
        {
            stage = RiskWarningStage.findByName("已发布")
        }
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
